package com.zzw.httpclient;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private EditText et_username;
    private EditText et_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et_username = (EditText)findViewById(R.id.et_username);
        et_password = (EditText)findViewById(R.id.et_password);
    }

    public void HttpLoginGet(View view) {
        final String username = et_username.getText().toString().trim();
        final String password = et_password.getText().toString().trim();

        new Thread(){
            @Override
            public void run() {
                final String result = LoginService.loginByGet(username,password);
                if(result != null){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this,"result",Toast.LENGTH_SHORT).show();
                        }
                    });
                }else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this,"请求失败",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }
        }.start();
    }

    public void HttpLoginPost(View view) {
        final String username = et_username.getText().toString().trim();
        final String password = et_password.getText().toString().trim();
        new Thread(){
            @Override
            public void run() {
                final String result = LoginService.loginByPost(username,password);
                if(result != null){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this,"result",Toast.LENGTH_SHORT).show();
                        }
                    });
                }else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this,"请求失败",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }
        }.start();
    }
}
